package com.example.attendance_system.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/static/");
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        // 只将根路径和一级路径转发到 index.html
        // 明确排除 api 和 assets 等静态资源路径
        registry.addViewController("/").setViewName("forward:/index.html");
        // 限制转发的模式，避免无限递归
        registry.addViewController("/{x:^(?!index\\.html|api$|assets$|static$).*$}").setViewName("forward:/index.html");
    }
} 